from blog.models import Articles, Category
from django import template

# 自定义标签
register = template.Library()


# 最新文章标签
@register.simple_tag
def get_recent_posts(num=5):
    return Articles.objects.all().order_by('-created_time')[:num]


# 归档文章标签
@register.simple_tag
def archives():
    return Articles.objects.dates('created_time', 'month', order='DESC')


# 分类标签
@register.simple_tag
def get_categories():
    return Category.objects.all()
